import { Controller, Post, UseInterceptors, UploadedFile, UseGuards, Body } from '@nestjs/common'
import { FileInterceptor } from '@nestjs/platform-express'
import { OssService } from './oss.service'
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiOperation, ApiTags } from '@nestjs/swagger'
import { OssDto } from './dto/oss.dto'
import { JwtAuthGuard } from '@/src/auth/guards/jwt-auth.guard'
import { RateLimit } from '../rateLimit/rate-limit.decorator'

@ApiTags('common')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth('JWT')
@Controller('common')
export class OssController {
  constructor(private readonly ossService: OssService) { }

  // 文件上传接口
  @Post('upload')
  @ApiOperation({ summary: '上传' })
  @ApiConsumes('multipart/form-data') // 声明接收表单数据
  @RateLimit(5, 60 * 1000)
  @ApiBody({ description: '', type: OssDto })
  @UseInterceptors(FileInterceptor('file'))
  async uploadFile(@UploadedFile() file: Express.Multer.File, @Body() ossDto: OssDto) {
    return this.ossService.uploadFile(file, ossDto.folder)
  }
}
